import {mapMutations} from 'vuex'

export default {
    ...mapMutations([
        'upToken',
		'upUserInfo'
    ]),
	handlerChoose(){
		this.agree = !this.agree
	},
	toLogin(){
		uni.navigateTo({
			url: '/pages/publics/login'
		})
	},
	//用户协议
	toUserAgreement(){
		uni.navigateTo({
			url: '/pages/publics/userAgreement'
		})
	},
	privacyAgreement(){
		uni.navigateTo({
			url: '/pages/publics/privacyAgreement'
		})
	},
	
	// toLogin() {
	// 	let that = this;
	// 	uni.getUserInfo({
	// 		success: (res1) => {
	// 			uni.login({
	// 				success: (res) => {
	// 					if (res.code) {
	// 						that.$httpRequest.request({
	// 							url: 'publics/login',
	// 							params: {
	// 								code: res.code,
	// 								userInfo: res1.userInfo,
	// 							},
	// 							success: res => {
	// 								// that.loading = false
	// 								if (res.code === that.$httpConfig.SUCCESS_CODE) {
	// 									that.upToken(res.data.token);
	// 									that.upUserInfo(res.data.userInfo);
	// 									uni.navigateBack({
	// 									    delta: 1
	// 									});
	// 								} else {
	// 									that.$toast.alert({
	// 										content: res.message,
	// 										callback: result => {
							
	// 										}
	// 									})
	// 								}
	// 							}
	// 						})
	// 					}
	// 				}
	// 			})
	// 		},
	// 		fail: () => {
	// 			console.log("未授权");
	// 			that.upUserInfo({});
	// 		}
	// 	})
	// },
    submitForm() {
        let that = this
        if (that.loading) {
            that.$toast.msg('请求中...', {
                icon: 1
            })
            return false
        }
        that.loading = true
			that.$httpRequest.request({
			    that: that,
			    url: 'h5/register',
			    params: that.formData,
			    success: res => {
			        that.loading = false
			        if (res.code === that.$httpConfig.SUCCESS_CODE) {
						uni.navigateTo({
							url:'/pages/publics/login'
						})
			            
			        } else {
			            that.$toast.alert({
			                content: res.message,
			                callback: result => {

			                }
			            })
			        }
			    }
			})

    },
	getCode() {
	    let that = this
		
	    if (that.loading) {
	        that.$toast.msg('请求中...', {
	            icon: 1
	        })
	        return false
	    }
	    that.loading = true
		
	    that.$httpRequest.request({
	        that: that,
	        url: 'h5/sendSms',
	        params: {
	            phone: that.formData.phone,
				type:1,//1 注册，2 忘记密码
	        },
	        success: res => {
	            that.loading = false

				
	            if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.getTxt = 60
					that.loopNum()
	            }else{
					that.$toast.msg(res.message, {
					  icon: 1
					})
				}
	        }
	    })
	},
	loopNum() {
		let that = this
	    that.intervalObj = setInterval(() => {
			that.num--
			if (that.num <= 0) {
				clearInterval(that.intervalObj)
				that.num = 60
				that.getTxt = "获取"
			}
	    }, 1000)
		
	},
	toOtherLogin(){
		uni.navigateTo({
			url: '/pages/publics/otherLogin'
		})
	},
	toReset(){
		uni.navigateTo({
			url: '/pages/publics/reset'
		})
	},
}
